<template>
  <div class="nav-root">
    <section class="nav-logo">
      <img src="@/assets/sjlr.png" alt="">
    </section>
    <el-dropdown>
      <span class="el-dropdown-link" @click="handleClick">
        <el-avatar v-if="headImg" :src="headImg"></el-avatar>
        <el-avatar v-else>{{ name }}</el-avatar>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item icon="el-icon-user">{{ name }}</el-dropdown-item>
        <el-dropdown-item icon="el-icon-switch-button" @click.native="handleLogout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  props: ['headImg'],
  data() {
    return {
      name: ''
    }
  },
  created() {
    this.name = JSON.parse(sessionStorage.getItem('user')).name
  },
  methods: {
    handleClick() {
      this.$message.warning('功能待开发')
    },
    handleLogout() {
      this.$router.push('/login');
      sessionStorage.removeItem("user");
    }
  }
}
</script>

<style scoped>
.nav-root {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.nav-logo {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  width: 400px;
  overflow: hidden;
  height: 50px;
}

.nav-logo img {
  height: 70px;
  margin-left: -30px;
  cursor: pointer;
}

.nav-logo span {
  display: inline-block;
  font-size: 20px;
  font-weight: bold;
  margin-left: 10px;
}

.el-avatar {
  z-index: 99;
  cursor: pointer;
  transition: all 0.5s;
}
.el-avatar:hover {
  box-shadow: 0 0 20pxpx rgba(79, 220, 242, 0.5);
}
</style>